const Exchange = artifacts.require('Exchange.sol')
const MinminToken = artifacts.require('MinminToken.sol')


module.exports = async function(callback) {
  const minminToken = await MinminToken.deployed()
  const exchange = await Exchange.deployed()
  const accounts = await web3.eth.getAccounts()

  // await exchange.depositEther({
  //   from: accounts[0],
  //   value: toWei(10)
  // })

  // 授权给交易所500从当前账号
  await minminToken.approve(exchange.address, toWei(500), {
    from: accounts[0]
  })

  await exchange.depositToken(minminToken.address, toWei(500), {
    from: accounts[0]
  })

  let res = await exchange.tokens(minminToken.address, accounts[0])
  console.log(fromWei(res));

  callback()
}


function fromWei(val) {
  return web3.utils.fromWei(val, 'ether')
}

function toWei(val) {
  return web3.utils.toWei(val.toString(), 'ether')
}